package Atm01;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 取款界面
 */
public class GetPanel extends JPanel implements ActionListener {
    private ATMFrame atmFrame;
    private JLabel  getmoneyLabel = new JLabel("取款金额：");
    private JTextField getmoneyField=new JTextField();
    private ImageIcon sureImg= new ImageIcon("Images/buttonSure.jpg");


    private Font font = new Font("黑体",Font.BOLD,30);

    private JButton sureBth= new JButton(sureImg);

    public GetPanel(ATMFrame atmFrame){
        this.atmFrame=atmFrame;

        this.setLayout(null);
        sureBth.setBounds(580,300,150,50);
        sureBth.addActionListener(this);

        getmoneyField.setBounds(400,200,330,50);
        getmoneyField.setFont(font);

        getmoneyLabel.setBounds(250,200,400,50);
        getmoneyLabel.setFont(font);
        this.add(getmoneyField);
        this.add(getmoneyLabel);
        this.add(sureBth);
        this.setOpaque(false);

       }


    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==sureBth){
            User user = atmFrame.getLoginUser();
            if(Double.parseDouble(getmoneyField.getText())>user.getBlance()){
                System.out.println("输入金额大于存款");
            }else{
                user.setBlance(user.getBlance() -Double.parseDouble(getmoneyField.getText()));
                atmFrame.switchPanel("menu");
            }

        }
    }
}
